package com.zhgxi.zf.service;

import java.util.List;

import javax.annotation.Resource;

import com.zhgxi.zf.entity.Dept;

import org.slave4j.orm.Filtration;
import org.slave4j.orm.Filtration.MatchType;
import org.slave4j.orm.hibernate.BaseDao;
import org.slave4j.orm.hibernate.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
@Service
@Transactional
public class DeptService extends BaseService<Dept>
{
	@Override
	@Resource(name="deptDao")
	public void setBaseDao(BaseDao<Dept> baseDao)
	{
		this.baseDao = baseDao;
	}
	
	public List<Dept> findAllDept(){
		Filtration visible = new Filtration(MatchType.EQ, true, "visible");
		List<Dept> list = baseDao.findList(visible);
		return list;
	} 
	
	public boolean deleteDept(Dept d) {
		try {
			baseDao.unVisible(d.getId());
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	public List<Dept> findByDname(String name){
		Filtration filter = new Filtration(MatchType.LIKE, name, "name");
		Filtration visible = new Filtration(MatchType.EQ, true, "visible");
		return baseDao.findList(filter,visible);
	}
	
}
